package com.atguigu.springcloud.commons.entities;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author horay
 * @category Class description
 * @email horay_hyc@qq.com
 * @date 2018/6/9 17:45
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public Result(com.atguigu.springcloud.commons.emums.Result result) {
        this.code = result.code;
        this.message = result.comment;
    }

    public Result(com.atguigu.springcloud.commons.emums.Result result, T data) {
        this.code = result.code;
        this.message = result.comment;
        this.data = data;
    }

    public static Result ok() {
        return new Result(com.atguigu.springcloud.commons.emums.Result.Success);
    }

    public static <T> Result ok(T data) {
        return ok().setData(data);
    }

    public static Result error() {
        return new Result(com.atguigu.springcloud.commons.emums.Result.Failure);
    }

    public static <T> Result error(T data) {
        return error().setData(data);
    }

    public static <T> Result error(com.atguigu.springcloud.commons.emums.Result result, T data) {
        return new Result(result, data);
    }

}
